package com.gzy.literature.dao;

import com.gzy.literature.entity.WorkCategories;
import org.apache.ibatis.annotations.*;
import org.springframework.data.domain.Pageable;
import java.util.List;


public interface WorkCategoriesDao {

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Select("SELECT * FROM work_categories WHERE id = #{id}")
    @Results(id = "workCategoriesResultMap", value = {
            @Result(property = "id", column = "id"),
            @Result(property = "categoryName", column = "category_name")
    })
    WorkCategories queryById(Integer id);

    /**
     * 查询指定行数据，带分页
     *
     * @param workCategories 查询条件
     * @return 对象列表
     */
    @Select("SELECT * FROM work_categories WHERE 1=1 " +
            "<if test='workCategories.categoryName != null'> AND category_name LIKE CONCAT('%', #{workCategories.categoryName}, '%')</if>")
    @Results(id = "workCategoriesResultMapPaged", value = {
            @Result(property = "id", column = "id"),
            @Result(property = "categoryName", column = "category_name")
    })
    List<WorkCategories> queryGll(@Param("workCategories") WorkCategories workCategories);

    /**
     * 统计总行数
     *
     * @param workCategories 查询条件
     * @return 总行数
     */
    @Select("SELECT COUNT(*) FROM work_categories WHERE 1=1 " +
            "<if test='workCategories.categoryName != null'> AND category_name LIKE CONCAT('%', #{workCategories.categoryName}, '%')</if>")
    long count(@Param("workCategories") WorkCategories workCategories);

    /**
     * 新增数据
     *
     * @param workCategories 实例对象
     * @return 影响行数
     */
    @Insert("INSERT INTO work_categories(id, category_name) VALUES(#{id}, #{categoryName})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(WorkCategories workCategories);

    /**
     * 修改数据
     *
     * @param workCategories 实例对象
     * @return 影响行数
     */
    @Update("UPDATE work_categories SET category_name = #{categoryName} WHERE id = #{id}")
    int update(WorkCategories workCategories);

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 影响行数
     */
    @Delete("DELETE FROM work_categories WHERE id = #{id}")
    int deleteById(Integer id);
}
